package sp.whereru;

public final class GeoHelper {

	private GeoHelper() {}

	public static Loc WebMercatorToGeographic(double mercatorX, double mercatorY)
	{
		if ((mercatorX < -20037508.3427892) || (mercatorX > 20037508.3427892)) {
			System.out.println("Point does not fall within a valid range of the mercator projection.");
		}
		double x = mercatorX;
		double y = mercatorY;
		double num3 = x / 6378137.0;
		double num4 = num3 * 57.295779513082323;
		double num5 = Math.floor((double)((num4 + 180.0) / 360.0));
		double num6 = num4 - (num5 * 360.0);
		double num7 = 1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * y) / 6378137.0)));

		double lat = num6;
		double lon = num7*57.295779513082323;

		Loc loc = new Loc(lat, lon);
		return loc;
	}

	/*
	private void GeographicToWebMercator(double lat, double lon)
	{
		if ((lat < -90.0) || (lon > 90.0))
		{
			System.out.println("Point does not fall within a valid range of a geographic coordinate system.");
		}
		double num = lat * 0.017453292519943295;
		double x = 6378137.0 * num;
		double a = lon * 0.017453292519943295;

		double mercatorX = x;
		double mercatorY = 3189068.5*Math.log((1.0 + Math.sin(a))/(1.0 - Math.sin(a)));
		
		//TODO return mercator points
	}
	*/
}
